package com.mzw.huaxiarealestatebackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.StaffKpiRecord;
import com.mzw.huaxiarealestatebackend.entity.StaffWorkRecord;
import com.mzw.huaxiarealestatebackend.dao.StaffWorkRecordDao;
import com.mzw.huaxiarealestatebackend.service.StaffWorkRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (StaffWorkRecord)表服务实现类
 *
 * @author makejava
 * @since 2023-12-22 00:03:04
 */
@Service("staffWorkRecordService")
public class StaffWorkRecordServiceImpl implements StaffWorkRecordService {
    @Resource
    private StaffWorkRecordDao staffWorkRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param stfwNo 主键
     * @return 实例对象
     */
    @Override
    public StaffWorkRecord queryById(String stfwNo) {
        QueryWrapper<StaffWorkRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("stfw_no", stfwNo);
        StaffWorkRecord staffWorkRecord = staffWorkRecordDao.selectOne(queryWrapper);
        return staffWorkRecord;
    }

    /**
     * 分页查询
     * @param current    当前页码
     * @param size      分页大小
     * @return
     */
    @Override
    public BackPage<StaffWorkRecord> queryByPage(int current, int size) {
        BackPage<StaffWorkRecord> backPage= new BackPage<>();
        //创建Page对象，传递两个参数：当前页    每页显示记录数
        Page<StaffWorkRecord> page = new Page<>(current,size);
        //调用mp方法实现分页
        staffWorkRecordDao.selectPage(page,null);
        //IPage<User> pageModel = userMapper.selectPage(page,null);
        backPage.setContentList(page.getRecords());
        backPage.setCurrentPage(page.getCurrent());
        backPage.setTotalPage(page.getPages());
        backPage.setTotalNum(page.getTotal());
        return backPage;
    }

    /**
     * 新增数据
     *
     * @param staffWorkRecord 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(StaffWorkRecord staffWorkRecord) {
        int insert = this.staffWorkRecordDao.insert(staffWorkRecord);
        return insert > 0;
    }

    /**
     * 修改数据
     *
     * @param staffWorkRecord 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(StaffWorkRecord staffWorkRecord) {
        int update = this.staffWorkRecordDao.update(staffWorkRecord);
        return update > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param stfwNo 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String stfwNo) {
        return this.staffWorkRecordDao.deleteById(stfwNo) > 0;
    }
}
